package com.bruce.ai.alibaba.observability.zipkin.controller;


import java.util.List;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.embedding.DashScopeEmbeddingOptions;

import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.embedding.EmbeddingRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试 EmbeddingModel 功能
 */
@RestController
@RequestMapping("/observability/embedding")
public class EmbeddingModelController {

	private final EmbeddingModel embeddingModel;

	public EmbeddingModelController(EmbeddingModel embeddingModel) {
		this.embeddingModel = embeddingModel;
	}

	@GetMapping
	public String embedding() {

		float[] embeddings = embeddingModel.embed("hello world.");
		return "embedding vector size:" + embeddings.length;
	}

	@GetMapping("/generic")
	public String embeddingGenericOpts(@RequestParam(value = "message", defaultValue = "介绍一下你自己") String message) {

        float[] embeddings = embeddingModel.call(new EmbeddingRequest(
                List.of(message),
                DashScopeEmbeddingOptions.builder().withModel("text-embedding-v3").build())
        ).getResult().getOutput();
		return "embedding vector size:" + embeddings.length;
	}

}
